package market

import (
	"go_server/game_server/api/service"
	"go_server/game_server/event_manager"
	"go_server/game_server/event_manager/event_data"
	"go_server/zinx/zlog"
)

type MarketService struct {
	service.AbsService

	MarketShow     *MarketShowApi
	MarketExchange *MarketExchangeApi

	eventMethods map[event_data.EventType]func(event event_data.IEvent)
}

const UN_LIMIT_TIMES_ITEM_TYPE = 1 // 无限购次数商品类型

var (
	ServiceObj *MarketService
)

func init() {
	ServiceObj = &MarketService{
		MarketShow:     &MarketShowApi{},
		MarketExchange: &MarketExchangeApi{},

		eventMethods: make(map[event_data.EventType]func(event event_data.IEvent)),
	}

	event_manager.EventManagerObj.AddServiceEvent(event_data.SummonHeroEvent, onSummonHeroEvent, ServiceObj) //监听英雄招募事件，测试
}

func (s *MarketService) GetModuleName() string {
	return "market"
}

func (s *MarketService) GetEventHandleFunc(eventType event_data.EventType) (func(event event_data.IEvent), bool) {
	eventFunc, ok := s.eventMethods[eventType]
	if !ok {
		zlog.Errorf("GetEventHandleFunc Err!!! method not found!! eventType: %d", eventType)
		return nil, false
	}
	return eventFunc, true
}

func (s *MarketService) GetEventMap() map[event_data.EventType]func(event event_data.IEvent) {
	return s.eventMethods
}

func onSummonHeroEvent(event event_data.IEvent) {
	/*conn := event.GetRoleConn()
	roleId, ok := event.GetRoleId()
	if !ok {
		return
	}

	ServiceObj.MarketExchange.TestHandle(roleId, conn)
	ServiceObj.MarketShow.TestHandle(roleId, conn)*/
}
